<template>
  <div class="role">
    <div class="common">
      <div class="common-button" @click="editHit(0)">新增</div>
    </div>

    <div class="table" v-loading="loading">
      <el-table
        :data="tableData"
        border
        :header-cell-style="{
          color: '#333333',
          backgroundColor: '#f3f3f3',
        }"
      >
        <el-table-column prop="managerRoleName" label="角色名称" width="200">
        </el-table-column>
        <el-table-column prop="managerRoleDesc" label="角色描述">
        </el-table-column>
        <el-table-column prop="" label="是否超管" width="200">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.isAdmin == 0" type="info">否</el-tag>
            <el-tag v-if="scope.row.isAdmin == 1" type="success">是</el-tag>
          </template>
        </el-table-column>

        <el-table-column prop="createTime" label="创建时间" width="200">
        </el-table-column>

        <el-table-column fixed="right" label="操作" width="200">
          <template slot-scope="scope">
            <div class="operation">
              <div class="list" @click.prevent="editHit(1, scope.row)">
                编辑
              </div>

              <div class="list" @click.prevent="deteleHit(scope.row)">删除</div>
            </div>
          </template>
        </el-table-column>
      </el-table>

      <div class="pagination">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          background
          layout="prev, pager, next"
          :total="tableDataTotal"
          :current-page="page"
        >
        </el-pagination>
      </div>
    </div>

    <!--删除弹出框-->
    <div class="delete">
      <el-dialog
        title="删除"
        :visible.sync="deleteVisible"
        :before-close="deleteClose"
      >
        <div class="delete-title">是否确认删除？</div>
        <div class="delete-attachment">
          <div class="list" @click="deleteClose">取消</div>
          <div class="list" @click="deleteConfirm">确定</div>
        </div>
      </el-dialog>
    </div>
  </div>
</template>

<script>
import { systemRoleList, systemRoleListDelete } from "@/api/system";

export default {
  data() {
    return {
      commonValue: "",
      commonDate: [],
      //-------------
      page: 1,
      limit: 10,
      tableData: [],
      tableDataTotal: 0,
      //--------
      deleteVisible: false,
      deleteObj: {},
      //----------------------动态
      loading: false,
    };
  },

  created() {
    this.loading = true;
    this.systemRoleListMet();
  },
  methods: {
    systemRoleListMet() {
      let params = {
        pageSize: this.limit,
        pageNo: this.page,
      };

      systemRoleList(params).then((res) => {
        if (res.errorCode == null) {
          this.tableData = res.resultData;
          this.tableDataTotal = res.resultData.length;
          this.loading = false;
        }
      });
    },
    //------------
    editHit(index, item) {
      if (index == 0) {
        this.$router.push({
          path: "/system/role-relevance",
        });
      } else {
        this.$router.push({
          path: "/system/role-relevance",
          query: {
            id: item.managerRoleId,
          },
        });
      }
    },
    deteleHit(item) {
      this.deleteObj = item;
      this.deleteVisible = true;
    },

    deleteClose() {
      this.deleteVisible = false;
    },
    deleteConfirm() {
      let params = this.deleteObj.managerRoleId;

      systemRoleListDelete(params).then((res) => {
        if (res.errorCode == null) {
           this.deleteVisible = false;
          this.$message.success("删除成功！");

          this.systemRoleListMet();
        }
      });
    },
    //---------
    handleSizeChange(val) {
      this.limit = val;
      this.systemRoleListMet();
    },
    handleCurrentChange(val) {
      this.page = val;
      this.systemRoleListMet();
    },
  },
};
</script>

<style lang="less" scoped>
@import url("@/assets/css/delete.less");

.role {
  .common {
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    .common-button {
      padding: 9px 20px;
      box-sizing: border-box;
      border-radius: 5px;
      background: #2a82e4;
      font-size: 14px;
      color: #fff;
      cursor: pointer;
      margin-left: 0;
    }
  }

  .table {
    cursor: pointer;

    .operation {
      display: flex;
      align-items: center;
      color: #2a82e4;

      .list {
        margin-right: 20px;
        cursor: pointer;
      }
    }

    .pagination {
      height: 70px;
      display: flex;
      align-items: center;
      justify-content: flex-end;
      padding-right: 60px;
      box-sizing: border-box;

      /deep/ .el-pagination.is-background .el-pager li {
        border: 1px solid #f4f4f5;
      }

      /deep/ .el-pager li {
        border: 1px solid #f4f4f5;
      }

      /deep/ .el-pagination.is-background .btn-prev {
        border: 1px solid #f4f4f5;
      }
    }
  }
}
</style>